package com.gugu.procedure.exceptions;

import com.gugu.procedure.common.MessageResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;


@Slf4j
@ControllerAdvice
public class BusinessExceptionHandler {

    @ResponseBody
    @ExceptionHandler({Exception.class})
    public MessageResult handlerException(Exception ex) {
        log.error("[捕获到异常]记录", ex);
        if (ex instanceof BusinessException) {
            return MessageResult.error(ex.getMessage());
        }
        log.info("系统异常：" + ex.getMessage());
        return MessageResult.error("系统异常,请联系管理人员");
    }
}
